package com.sg.plmadapter.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.handlers.HandlerUtil;

import com.sg.business.model.Document;
import com.sg.business.model.Folder;
import com.sg.widgets.MessageUtil;

public class SyncPLMFolder extends AbstractHandler {

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IStructuredSelection is = (IStructuredSelection) HandlerUtil
				.getCurrentSelection(event);
		try {
			if (!is.isEmpty()) {
				Object firstElement = is.getFirstElement();
				if (firstElement instanceof Folder) {
					Folder folder = (Folder) firstElement;
					folder.syncPLMData();
				} else if (firstElement instanceof Document) {
					Document document = (Document) firstElement;
					document.syncPLMData();

				}
			}
		} catch (Exception e) {
			MessageUtil.showToast(e);
		}
		return null;
	}

}
